package org.finjic.context;

import org.finjic.callback.container.ContainerCallbackProcessor;
import org.finjic.factory.BeanFactory;

/**
 * User: Taras
 * Date: 04.11.12
 * Time: 13:30
 */
public abstract class AbstractApplicationContext implements ApplicationContext {
    private BeanFactory beanFactory;
    private ContainerCallbackProcessor callbackProcessor = new ContainerCallbackProcessor();

    @Override
    public Object getBean(String beanId) {
        if (beanFactory == null) {
            beanFactory = getBeanFactory();
        }
        return beanFactory.getBean(beanId);
    }

    protected void start(){
        callbackProcessor.start();
    }

    @Override
    public void shutdown() {
        callbackProcessor.shutdown();
    }

    protected abstract BeanFactory getBeanFactory();
}
